package com.pmsystem.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import com.pmsystem.pojo.Fix;
import com.pmsystem.pojo.User;
import com.pmsystem.service.FixService;
import com.pmsystem.util.BeanUtil;

@Controller
public class FixController {

	@Autowired
	private FixService fixService;
	
	/**
	 * 
	 * <p>Title: proposeFix</p >  
	 * <p>Description: 业主申请维修</p >  
	 * @author 泽强
	 * @param session
	 * @param fix
	 * @return
	 */
	@RequestMapping(value="user/proposeFix" , method=RequestMethod.POST)
	@ResponseBody
	public String proposeFix(HttpSession session,@RequestParam Map<String,Object> map) {
		User user = (User) session.getAttribute("user");
		Fix fix = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),Fix.class);
		fix.setUserId(user.getUserId());
		boolean flag=fixService.addFix(fix);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: updateFix</p >  
	 * <p>Description: 修改维修申请</p >  
	 * @author 泽强
	 * @param fix
	 * @return
	 */
	@RequestMapping(value= {"admin/updateFix","user/updateFix"} , method=RequestMethod.POST)
	@ResponseBody
	public Object updateFix(@RequestParam Map<String,Object> map) {
		
		Fix fix = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),Fix.class);	
		boolean flag=fixService.update(fix);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: findAllFix</p >  
	 * <p>Description: 二级管理员查找维修账单</p >  
	 * @author 泽强
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="admin/findAllFix" , method=RequestMethod.GET)
	@ResponseBody
	public Object findAllFix(Integer pageNo,Integer pageSize) {
		List<Fix> list=fixService.findAllFix(pageNo,pageSize);	
		return list;	
	}
	
	/**
	 * 
	 * <p>Title: findFix</p >  
	 * <p>Description: 按一定条件查找维修单，注意SQL语句</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	@RequestMapping(value="findFix" , method=RequestMethod.GET)
	@ResponseBody
	public Object findFix(@RequestParam Map<String,Object> map) {
		String startSendTime = (String) map.get("startSendTime");
		String endSendTime = (String)map.get("endSendTime");
		System.out.println(startSendTime+"----"+endSendTime);
		List<Fix> list=fixService.findFix(map);
		return list;
	}
	

}
